package com.senlingspace.web.controller.headquarters;

import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.senlingspace.system.domain.vo.SlkjTicketCategoryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.senlingspace.common.annotation.Log;
import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.enums.BusinessType;
import com.senlingspace.system.domain.SlkjTicketCategory;
import com.senlingspace.system.service.ISlkjTicketCategoryService;
import com.senlingspace.common.utils.poi.ExcelUtil;
import com.senlingspace.common.core.page.TableDataInfo;

/**
 * 票类管理Controller
 *
 * @author SenlingSpace
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/system/category")
public class SlkjTicketCategoryController extends BaseController {
    @Autowired
    private ISlkjTicketCategoryService slkjTicketCategoryService;

    /**
     * 查询票类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlkjTicketCategory slkjTicketCategory) {
        PageInfo<SlkjTicketCategoryVo> pageInfo = slkjTicketCategoryService.selectSlkjTicketCategoryList(slkjTicketCategory, true);
        return getDataTable(pageInfo);
    }

    /**
     * 导出票类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "票类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlkjTicketCategory slkjTicketCategory) {
        PageInfo<SlkjTicketCategoryVo> pageInfo = slkjTicketCategoryService.selectSlkjTicketCategoryList(slkjTicketCategory, false);
        ExcelUtil<SlkjTicketCategoryVo> util = new ExcelUtil<SlkjTicketCategoryVo>(SlkjTicketCategoryVo.class);
        util.exportExcel(response, pageInfo.getList(), "票类管理数据");
    }

    /**
     * 获取票类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(slkjTicketCategoryService.selectSlkjTicketCategoryById(id));
    }

    /**
     * 新增票类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "票类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlkjTicketCategory slkjTicketCategory) {
        slkjTicketCategory.setCreateBy(super.getUserId() + "");
        slkjTicketCategory.setDelFlag(0);
        return toAjax(slkjTicketCategoryService.insertSlkjTicketCategory(slkjTicketCategory));
    }

    /**
     * 修改票类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "票类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlkjTicketCategory slkjTicketCategory) {
        slkjTicketCategory.setUpdateBy(super.getUserId() + "");
        return toAjax(slkjTicketCategoryService.updateSlkjTicketCategory(slkjTicketCategory));
    }

    /**
     * 删除票类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "票类管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return slkjTicketCategoryService.deleteSlkjTicketCategoryByIds(ids, super.getUserId());
    }

}
